<!doctype html>
<link type="text/css" rel="stylesheet" href="css/main.css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"  type="text/javascript"></script>
<title>Web Worker Wars - JavaScript AI Game</title>
<div><a href="./">Home</a> <a href="http://code.google.com/p/web-worker-wars/">Project on Google Code</a></div>
<div id="field">Workers are fighting. Please wait...</div>
<script type="text/javascript" src="https://getfirebug.com/firebug-lite.js#startOpened=true"></script>
<script src="js/Game.js"></script>
<script>
(function (window) {
    if ('Worker' in window) {
        try {
            var options = window.location.hash.split('#')[1].split(';'),
                workers = window.location.hash.split('#')[1].split(';')[0].split('&'),
                parameters = {};
            if (!workers.length) {
                alert('Workers codes are required.');
            } else if (workers.length < 2) {
                alert('Minimum 2 workers are required.');
            } else {
                // checking worker names
                // .match(/^[A-Za-z0-9]{8,20}$/);
                for (var i = 0, c = workers.length, log = []; i < c; i +=1 ) {
                    if (!workers[i].match(/^[A-Za-z0-9]{8,20}$/)) {
                        log.push('Fail to load worker ' + workers[i]);
                    } else {
                        Sandbox.registerPlayer('js/workers/' + workers[i] + '.js');
                    }
                    if (log.length) {
                        alert(log.join("\n"));
                    }
                }
                if (options[1]) {
                    options = options[1].split(',');
                    for (i = 0, c = options.length; i < c; i += 1) {
                        options[i] = options[i].split('=');
                        parameters[options[i][0]] = options[i][1];
                    }
                }
                Sandbox.start(parameters);
            }
        } catch (e) {
            alert(e);
        }
    } else {
        alert('Web Worker War is impossible w/o Web Workers!\nTry another browser.');
    }
}(this));
</script>
